package com.ningju.procurement.core.questionnaire.service;

import com.ningju.procurement.common.service.BaseServiceImpl;
import com.ningju.procurement.core.questionnaire.bean.Dimension;
import com.ningju.procurement.core.questionnaire.dao.DimensionDao;
import com.ningju.procurement.core.questionnaire.dao.DimensionSegmentDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 题目纬度解释管理
 */
@Service
public class DimensionService extends BaseServiceImpl<DimensionDao, Dimension> {

    @Autowired
    private DimensionDao dimensionDao;

    @Autowired
    private DimensionSegmentDao dimensionSegmentDao;

    public boolean save(Dimension dimension) {
        return super.save(dimensionDao, dimension);
    }

    @Transactional
    public boolean destory(Dimension dimension) {

        //删除纬度解释所有的分段解释
        dimension.getSegmentList().forEach((segment) -> {
            dimensionSegmentDao.deleteById(segment.getId());
        });

        return dimensionDao.deleteById(dimension.getId()) > 0;
    }

}
